package com.lizhenhua.fmmall.controller;

import com.lizhenhua.fmmall.entity.IndexImg;
import com.lizhenhua.fmmall.service.IndexImgService;
import com.lizhenhua.fmmall.service.serviceImpl.CategoryServiceImpl;
import com.lizhenhua.fmmall.service.serviceImpl.IndexImgServiceImpl;
import com.lizhenhua.fmmall.service.serviceImpl.ProductServiceImpl;
import com.lizhenhua.fmmall.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/index")
@Api(value = "首页数据显示接口", tags = "主页面管理")
public class IndexController {

    @Autowired
    private IndexImgServiceImpl indexImgService;

    @Autowired
    private CategoryServiceImpl categoryService;


    @Autowired
    private ProductServiceImpl productService;

    @ApiOperation("主页轮播图接口")
    @GetMapping("/indeximg")
    private ResultVo indexImgs() {

        ResultVo resultVo = indexImgService.listIndexImgs();
        return resultVo;
    }

    @GetMapping("/list-recommends")
    @ApiOperation("商品推荐接口")
    public ResultVo recommendList() {

        return productService.selectProductAndImg();
    }

    @GetMapping("/category-list/{parentId}")
    @ApiOperation("商品分类的查询接口")
    @ApiImplicitParams({
//       dataType数据类型     required = true 必须填写  defaultValue默认值

            @ApiImplicitParam(dataType = "Integer", name = "parentId", value = "父类id", required = true,defaultValue = "0")
    })
    private ResultVo listCategory(@PathVariable("parentId") Integer parentId) {

        return categoryService.selectAllCategories2(parentId);
    }


    @GetMapping("/category-rmdSort")
    @ApiOperation("分类推荐商品接口")
    public ResultVo selectFirstLevel() {
        return categoryService.selectFirstLevel();
    }






}
